package com.wc5818.wcImgPath.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wc5818.common.AjaxResult;
import com.wc5818.wcBasicInfo.entity.WcBasicInfo;
import com.wc5818.wcImgPath.entity.WcImgPath;
import com.wc5818.wcImgPath.mapper.WcImgPathMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-02-22
 */
@RestController
@RequestMapping("/wcImgPath")
public class WcImgPathController {
    @Autowired
    WcImgPathMapper wcImgPathMapper;

    @GetMapping("refreshFieldStatus")
    public Object refreshFieldStatus(String orderNum) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        List list = wcImgPathMapper.selectList(new QueryWrapper<WcImgPath>().eq("orderId", orderNum));
        if(list != null  && list.size() > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(list.get(0));

        }

        return ajaxResult;
    }

    @GetMapping("getByOrderId")
    public Object getByOrderId(String orderNum) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        List list = wcImgPathMapper.selectList(new QueryWrapper<WcImgPath>().eq("orderId", orderNum));
        if(list != null  && list.size() > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(list.get(0));

        } else {
            WcImgPath wcImgPath = new WcImgPath();
            wcImgPath.setOrderId(orderNum);
            if(wcImgPathMapper.insert(wcImgPath) > 0) {
                ajaxResult.setSuccess(true);
                ajaxResult.setData(wcImgPath);
            }
        }

        return ajaxResult;
    }
}
